<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="16">
        <el-card class="box-card" shadow="hover">
          <div slot="header" class="clearfix">
            <span>新增跟进</span>
          </div>
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="跟进内容" prop="traceOrderContent">
              <el-input
                v-model="form.traceOrderContent"
                type="textarea"
                placeholder="请输入内容"
              />
            </el-form-item>
            <el-form-item label="下次跟进时间" prop="traceOrderNextTime">
              <el-date-picker
                style="width: 100%"
                clearable
                v-model="form.traceOrderNextTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择下次跟进时间"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item class="dialog-footer" v-if="!disabled">
              <el-button type="primary" @click="submitForm">确 定</el-button>
              <el-button @click="cancel">取 消</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="box-card" shadow="hover">
          <div slot="header" class="clearfix">
            <span>跟进记录</span>
          </div>
          <el-timeline>
            <el-timeline-item
              v-for="trace in traceList"
              :key="trace.traceId"
              :timestamp="trace.traceOrderTime"
            >
              <div style="word-wrap: break-word">
                {{ trace.traceOrderContent }}
              </div>
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  addTrace,
  updateTrace,
  getOrderTraceListNotPage,
} from "@/api/crm/trace";
export default {
  name: "Trace",
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      traceList: [],
    };
  },
  props: {
    orderId: {
      type: String,
      default: "",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  created() {
  },
  methods: {
    cancel() {
      this.reset();
      this.$emit("cancel");
    },
    getData() {
      getOrderTraceListNotPage({ orderId: this.orderId?.split("_")[0] }).then(
        (res) => {
          this.traceList = res.data;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        traceOrderId: null,
        traceOrderContent: null,
        traceOrderTime: null,
        traceOrderBy: null,
        traceOrderNextTime: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.orderId = this.orderId?.split("_")[0];
          addTrace(this.form).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.getData();
          });
        }
      });
    },
  },
};
</script>

<style scoped>
.box-card {
  min-height: 82vh;
}
</style>